package longestCommonPrefix;

public class Way1 {

	public static void main(String[] args) throws Exception {
		System.out.println(new Way1().longestCommonPrefix(new String[] { "flower", "flow", "flight" }));
	}

	public String longestCommonPrefix(String[] strs) {
		if (strs == null)
			return "";
		String temp = strs[0];
		for (int i = 1; i < strs.length; i++) {
			while (temp.length() != 0 && !strs[i].startsWith(temp)) {
				temp = temp.substring(0, temp.length() - 1);
			}
			if (temp.equals(""))
				return temp;
		}
		return temp;
	}

}